<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>竞赛总结：智能驾驶汽车虚拟仿真视频数据理解 | SanShui的个人博客</title><meta name="author" content="SanShui"><meta name="copyright" content="SanShui"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="2023全球智能汽车AI挑战赛——赛道二：智能驾驶汽车虚拟仿真视频数据理解赛道">
<meta property="og:type" content="article">
<meta property="og:title" content="竞赛总结：智能驾驶汽车虚拟仿真视频数据理解">
<meta property="og:url" content="https://huaiyuechusan.github.io/archives/283f9737.html">
<meta property="og:site_name" content="SanShui的个人博客">
<meta property="og:description" content="2023全球智能汽车AI挑战赛——赛道二：智能驾驶汽车虚拟仿真视频数据理解赛道">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://wallpaper.csun.site/?15">
<meta property="article:published_time" content="2024-01-14T13:59:00.000Z">
<meta property="article:modified_time" content="2024-10-17T12:00:16.756Z">
<meta property="article:author" content="SanShui">
<meta property="article:tag" content="深度学习">
<meta property="article:tag" content="竞赛">
<meta property="article:tag" content="CV">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://wallpaper.csun.site/?15"><link rel="shortcut icon" href="/./img/config_img/%E9%98%B3%E5%85%89%E5%B0%8F%E7%8C%AB.jpg"><link rel="canonical" href="https://huaiyuechusan.github.io/archives/283f9737"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '竞赛总结：智能驾驶汽车虚拟仿真视频数据理解',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-10-17 20:00:16'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><script src="https://npm.elemecdn.com/echarts@4.9.0/dist/echarts.min.js"></script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Zfour/Butterfly-double-row-display@1.00/cardlistpost.min.css"/>
<style>#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags:before {content:"\A";
  white-space: pre;}#recent-posts > .recent-post-item >.recent-post-info > .article-meta-wrap > .tags > .article-meta__separator{display:none}</style>
<link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-categories-card@1.0.0/lib/categorybar.css"><link rel="stylesheet" href="/./css/runtime.css" media="print" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/atom.xml" title="SanShui的个人博客" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (true) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/./img/config_img/%E9%98%B3%E5%85%89%E5%B0%8F%E7%8C%AB.jpg" onerror="onerror=null;src='./img/config_img/蓝天.jpg'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">16</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-envelope-open"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('http://wallpaper.csun.site/?15')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">SanShui的个人博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/comments/"><i class="fa-fw fas fa-envelope-open"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">竞赛总结：智能驾驶汽车虚拟仿真视频数据理解</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-01-14T13:59:00.000Z" title="发表于 2024-01-14 21:59:00">2024-01-14</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-10-17T12:00:16.756Z" title="更新于 2024-10-17 20:00:16">2024-10-17</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E7%AB%9E%E8%B5%9B/">竞赛</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">7.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>31分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="竞赛总结：智能驾驶汽车虚拟仿真视频数据理解"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><meta name="referrer" content="no-referrer" />

<h1 id="竞赛总结：智能驾驶汽车虚拟仿真视频数据理解"><a href="#竞赛总结：智能驾驶汽车虚拟仿真视频数据理解" class="headerlink" title="竞赛总结：智能驾驶汽车虚拟仿真视频数据理解"></a>竞赛总结：智能驾驶汽车虚拟仿真视频数据理解</h1><ul>
<li>赛题名称：2023全球智能汽车AI挑战赛——赛道二：智能驾驶汽车虚拟仿真视频数据理解赛道</li>
<li>赛题任务：对视频中的信息进行综合理解，以指定的json文件格式，按照数据说明中的关键词（key）填充描述型的文本信息</li>
<li>赛题类型：计算机视觉、目标检测</li>
</ul>
<blockquote>
<p>比赛链接：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://tianchi.aliyun.com/competition/entrance/532155">2023全球智能汽车AI挑战赛——赛道二：智能驾驶汽车虚拟仿真视频数据理解赛道</a></p>
<p>Datawhale教学视频：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://space.bilibili.com/431850986/channel/collectiondetail?sid=1901397">二次元的Datawhale的个人空间-二次元的Datawhale个人主页)</a></p>
</blockquote>
<h2 id="赛事背景"><a href="#赛事背景" class="headerlink" title="赛事背景"></a>赛事背景</h2><p>当前，全球新一轮科技革命和产业变革蓬勃发展，汽车与人工智能技术加速融合，电动化、网联化、智能化成为汽车产业的发展潮流和趋势，AI技术将更广泛地和汽车产业的各个领域，应用于汽车的智能维护、智能制造、智能驾驶等诸多方面。作为人工智能技术和汽车产业先进技术的倡导者，吉利汽车集团、阿里云、NVIDIA 英伟达一直致力于推动未来出行方式的发展，共同发起了本届2023全球智能汽车AI挑战赛。本届比赛将汇聚来自全球各地的杰出AI领域人才，推动自动驾驶、AI大模型、加速计算、云计算技术三者深度结合，为未来智能出行提供更加安全、高效、舒适的解决方案。</p>
<h2 id="赛事任务"><a href="#赛事任务" class="headerlink" title="赛事任务"></a>赛事任务</h2><p>输入：元宇宙仿真平台生成的前视摄像头虚拟视频数据（8-10秒左右）；</p>
<p>输出：对视频中的信息进行综合理解，以指定的json文件格式，按照数据说明中的关键词（key）填充描述型的文本信息（value，中文/英文均可以）；</p>
<h2 id="数据说明"><a href="#数据说明" class="headerlink" title="数据说明"></a>数据说明</h2><h3 id="文本描述结构树"><a href="#文本描述结构树" class="headerlink" title="文本描述结构树"></a>文本描述结构树</h3><p><img src="https://gitee.com/huaiyuechusan/picture/raw/master/Typora/202401142149361.png" alt="image-20240114211932916"></p>
<h3 id="上传json格式示例"><a href="#上传json格式示例" class="headerlink" title="上传json格式示例"></a>上传json格式示例</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">建议用英文提交：</span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line"><span class="attr">&quot;author&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;abc&quot;</span> <span class="punctuation">,</span></span><br><span class="line"><span class="attr">&quot;time&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;YYMMDD&quot;</span><span class="punctuation">,</span></span><br><span class="line"><span class="attr">&quot;model&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;model_name&quot;</span><span class="punctuation">,</span></span><br><span class="line"><span class="attr">&quot;test_results&quot;</span> <span class="punctuation">:</span><span class="punctuation">[</span></span><br><span class="line">    <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;clip_id&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;xxxx_1&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;scenario&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;cityroad&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;weather&quot;</span><span class="punctuation">:</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;period&quot;</span><span class="punctuation">:</span><span class="string">&quot;night&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;road_structure&quot;</span><span class="punctuation">:</span><span class="string">&quot;ramp&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;general_obstacle&quot;</span><span class="punctuation">:</span><span class="string">&quot;nothing&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;abnormal_condition&quot;</span><span class="punctuation">:</span><span class="string">&quot;nothing&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;ego_car_behavior&quot;</span><span class="punctuation">:</span><span class="string">&quot;turning right&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;closest_participants_type&quot;</span><span class="punctuation">:</span><span class="string">&quot;passenger car&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;closest_participants_behavior&quot;</span><span class="punctuation">:</span><span class="string">&quot;braking&quot;</span></span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;clip_id&quot;</span> <span class="punctuation">:</span> <span class="string">&quot;xxxx_2&quot;</span></span><br><span class="line">    ... ...</span><br><span class="line">    <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">... ...</span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>
<p>为了减少程序编译过程中的问题，提交答案的json文件中的 key &amp; value 请使用英文，key请不要进行更改，value使用以下列表中的元素。</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">&quot;scenario&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;suburbs&quot;</span><span class="punctuation">,</span><span class="string">&quot;city street&quot;</span><span class="punctuation">,</span><span class="string">&quot;expressway&quot;</span><span class="punctuation">,</span><span class="string">&quot;tunnel&quot;</span><span class="punctuation">,</span><span class="string">&quot;parking-lot&quot;</span><span class="punctuation">,</span><span class="string">&quot;gas or charging stations&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;weather&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;clear&quot;</span><span class="punctuation">,</span><span class="string">&quot;cloudy&quot;</span><span class="punctuation">,</span><span class="string">&quot;raining&quot;</span><span class="punctuation">,</span><span class="string">&quot;foggy&quot;</span><span class="punctuation">,</span><span class="string">&quot;snowy&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;period&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;daytime&quot;</span><span class="punctuation">,</span><span class="string">&quot;dawn or dusk&quot;</span><span class="punctuation">,</span><span class="string">&quot;night&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;road_structure&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;normal&quot;</span><span class="punctuation">,</span><span class="string">&quot;crossroads&quot;</span><span class="punctuation">,</span><span class="string">&quot;T-junction&quot;</span><span class="punctuation">,</span><span class="string">&quot;ramp&quot;</span><span class="punctuation">,</span><span class="string">&quot;lane merging&quot;</span><span class="punctuation">,</span><span class="string">&quot;parking lot entrance&quot;</span><span class="punctuation">,</span><span class="string">&quot;round about&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;general_obstacle&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;nothing&quot;</span><span class="punctuation">,</span><span class="string">&quot;speed bumper&quot;</span><span class="punctuation">,</span><span class="string">&quot;traffic cone&quot;</span><span class="punctuation">,</span><span class="string">&quot;water horse&quot;</span><span class="punctuation">,</span><span class="string">&quot;stone&quot;</span><span class="punctuation">,</span><span class="string">&quot;manhole cover&quot;</span><span class="punctuation">,</span><span class="string">&quot;nothing&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;abnormal_condition&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;uneven&quot;</span><span class="punctuation">,</span><span class="string">&quot;oil or water stain&quot;</span><span class="punctuation">,</span><span class="string">&quot;standing water&quot;</span><span class="punctuation">,</span><span class="string">&quot;cracked&quot;</span><span class="punctuation">,</span><span class="string">&quot;nothing&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;ego_car_behavior&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;slow down&quot;</span><span class="punctuation">,</span><span class="string">&quot;go straight&quot;</span><span class="punctuation">,</span><span class="string">&quot;turn right&quot;</span><span class="punctuation">,</span><span class="string">&quot;turn left&quot;</span><span class="punctuation">,</span><span class="string">&quot;stop&quot;</span><span class="punctuation">,</span><span class="string">&quot;U-turn&quot;</span><span class="punctuation">,</span><span class="string">&quot;speed up&quot;</span><span class="punctuation">,</span><span class="string">&quot;lane change&quot;</span><span class="punctuation">,</span><span class="string">&quot;others&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;closest_participants_type&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;passenger car&quot;</span><span class="punctuation">,</span><span class="string">&quot;bus&quot;</span><span class="punctuation">,</span><span class="string">&quot;truck&quot;</span><span class="punctuation">,</span><span class="string">&quot;pedestrian&quot;</span><span class="punctuation">,</span><span class="string">&quot;policeman&quot;</span><span class="punctuation">,</span><span class="string">&quot;nothing&quot;</span><span class="punctuation">,</span><span class="string">&quot;others&quot;</span><span class="punctuation">,</span><span class="string">&quot;unknown&quot;</span><span class="punctuation">]</span></span><br><span class="line"><span class="attr">&quot;closest_participants_behavior&quot;</span> <span class="punctuation">:</span> <span class="punctuation">[</span><span class="string">&quot;slow down&quot;</span><span class="punctuation">,</span><span class="string">&quot;go straight&quot;</span><span class="punctuation">,</span><span class="string">&quot;turn right&quot;</span><span class="punctuation">,</span><span class="string">&quot;turn left&quot;</span><span class="punctuation">,</span><span class="string">&quot;stop&quot;</span><span class="punctuation">,</span><span class="string">&quot;U-turn&quot;</span><span class="punctuation">,</span><span class="string">&quot;speed up&quot;</span><span class="punctuation">,</span><span class="string">&quot;lane change&quot;</span><span class="punctuation">,</span><span class="string">&quot;others&quot;</span><span class="punctuation">]</span></span><br></pre></td></tr></table></figure>
<h2 id="评测指标"><a href="#评测指标" class="headerlink" title="评测指标"></a>评测指标</h2><p>初赛阶段：排行榜总分=视频理解准确度分数<br>复赛阶段：复赛总成绩=复赛排行榜视频理解准确度分数（100%）+代码复现时效分数（10%）<br>具体成绩计算方法和晋级标准请参考【赛制介绍】</p>
<p>视频理解准确度分数评测规则如下：</p>
<p>参赛者可采用不同的人工智能的模型和算法，推理出对应视频的描述语言，参赛者可以在给定的备选答案中选出一个正确的答案，如果其描述语言不在给定的备选答案中，也可以给出一个最佳的答案。</p>
<p>系统会针对参赛者提交的json文件，通过描述型的文本信息与真值进行对比，综合得出分数；其中，“距离最近的交通参与者的行为”的题目为2分，其它题目为1分；每个视频的满分为10分。每一个视频结果中的key值，需要参考数据说明的json格式示例，请勿进行修改。</p>
<p>对于真值部分，组织者会建立对应的中英文近义词作为真值列表，只要在该列表中就获得分数，例如真值“雨天” = [“雨天”， “雨”， “小雨”… , “rainy”, “rain”, “raining”…]，参赛选手可以选择对应的近义词来进行作答，但每一项的真值列表不公开，仅体现在后台程序中。</p>
<h2 id="解题思路"><a href="#解题思路" class="headerlink" title="解题思路"></a>解题思路</h2><h3 id="基本思路"><a href="#基本思路" class="headerlink" title="基本思路"></a>基本思路</h3><ul>
<li>使用文本与图像进行匹配</li>
</ul>
<p>datawhale学习组织将Baseline部署在线上平台百度AI Studio上，可一键fork运行代码：</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://aistudio.baidu.com/projectdetail/7033846?contributionType=1&amp;sUid=40990&amp;shared=1&amp;ts=1699415726984">https://aistudio.baidu.com/projectdetail/7033846?contributionType=1&amp;sUid=40990&amp;shared=1&amp;ts=1699415726984</a></p>
<p>baseline代码解读</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 导入必要的库和模块</span></span><br><span class="line"><span class="keyword">import</span> paddle  <span class="comment"># 导入 PaddlePaddle 深度学习框架</span></span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image  <span class="comment"># 从 PIL 库导入 Image 模块，用于图像处理</span></span><br><span class="line"><span class="keyword">from</span> clip <span class="keyword">import</span> tokenize, load_model  <span class="comment"># 导入 clip 模块，可能用于图像和文本的联合处理</span></span><br><span class="line"><span class="keyword">import</span> glob, json, os  <span class="comment"># 导入文件处理和 JSON 处理的库</span></span><br><span class="line"><span class="keyword">import</span> cv2  <span class="comment"># 导入 OpenCV 库，用于计算机视觉任务</span></span><br><span class="line"><span class="keyword">from</span> tqdm <span class="keyword">import</span> tqdm_notebook  <span class="comment"># 导入 tqdm_notebook 以在笔记本中显示进度条</span></span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np  <span class="comment"># 导入 NumPy 用于数值处理</span></span><br><span class="line"><span class="keyword">from</span> sklearn.preprocessing <span class="keyword">import</span> normalize  <span class="comment"># 从 sklearn.preprocessing 导入 normalize 用于数据归一化</span></span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt  <span class="comment"># 导入 matplotlib.pyplot 用于绘图</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 加载模型和转换工具</span></span><br><span class="line">model, transforms = load_model(<span class="string">&#x27;ViT_B_32&#x27;</span>, pretrained=<span class="literal">True</span>)  <span class="comment"># 加载预训练的 ViT_B_32 模型和其转换</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 为各个类别和相应词汇定义字典</span></span><br><span class="line">en_match_words = &#123;</span><br><span class="line">    <span class="comment"># 各个类别的关键词列表</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 初始化提交的 JSON 结构</span></span><br><span class="line">submit_json = &#123;</span><br><span class="line">    <span class="string">&quot;author&quot;</span>: <span class="string">&quot;abc&quot;</span>,  <span class="comment"># 作者姓名</span></span><br><span class="line">    <span class="string">&quot;time&quot;</span>: <span class="string">&quot;231011&quot;</span>,  <span class="comment"># 时间戳</span></span><br><span class="line">    <span class="string">&quot;model&quot;</span>: <span class="string">&quot;model_name&quot;</span>,  <span class="comment"># 使用的模型名称</span></span><br><span class="line">    <span class="string">&quot;test_results&quot;</span>: []  <span class="comment"># 测试结果的列表，初始为空</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取并排序视频路径</span></span><br><span class="line">paths = glob.glob(<span class="string">&#x27;./PreliminaryTestVideos/*&#x27;</span>)  <span class="comment"># 使用 glob 获取指定路径下的所有视频文件</span></span><br><span class="line">paths.sort()  <span class="comment"># 对路径进行排序</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 遍历每个视频文件进行处理</span></span><br><span class="line"><span class="keyword">for</span> video_path <span class="keyword">in</span> paths:</span><br><span class="line">    <span class="built_in">print</span>(video_path)  <span class="comment"># 打印视频路径</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 从路径中提取视频剪辑的 ID</span></span><br><span class="line">    clip_id = video_path.split(<span class="string">&#x27;/&#x27;</span>)[-<span class="number">1</span>]</span><br><span class="line">    cap = cv2.VideoCapture(video_path)  <span class="comment"># 使用 OpenCV 读取视频</span></span><br><span class="line">    img = cap.read()[<span class="number">1</span>]  <span class="comment"># 读取视频的第一帧</span></span><br><span class="line">    image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)  <span class="comment"># 将图像从 BGR 转换为 RGB 格式</span></span><br><span class="line">    image = Image.fromarray(image)  <span class="comment"># 将数组转换为 PIL 图像</span></span><br><span class="line">    image = transforms(image).unsqueeze(<span class="number">0</span>)  <span class="comment"># 应用预处理转换并添加一个维度</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 初始化用于单个视频结果的字典</span></span><br><span class="line">    single_video_result = &#123;</span><br><span class="line">        <span class="comment"># 视频的各种属性</span></span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 针对特定关键词进行预测</span></span><br><span class="line">    <span class="keyword">for</span> keyword <span class="keyword">in</span> en_match_words.keys():</span><br><span class="line">        <span class="keyword">if</span> keyword <span class="keyword">not</span> <span class="keyword">in</span> [<span class="string">&quot;weather&quot;</span>, <span class="string">&quot;road_structure&quot;</span>]:</span><br><span class="line">            <span class="keyword">continue</span>  <span class="comment"># 如果关键词不是 weather 或 road_structure，则跳过</span></span><br><span class="line">        </span><br><span class="line">        texts = np.array(en_match_words[keyword])  <span class="comment"># 将关键词转换为 NumPy 数组</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">with</span> paddle.no_grad():  <span class="comment"># 禁用梯度计算</span></span><br><span class="line">            <span class="comment"># 使用模型进行预测</span></span><br><span class="line">            logits_per_image, logits_per_text = model(image, tokenize(en_match_words[keyword]))</span><br><span class="line">            probs = paddle.nn.functional.softmax(logits_per_image, axis=-<span class="number">1</span>)  <span class="comment"># 应用 softmax 获取概率分布</span></span><br><span class="line"></span><br><span class="line">        probs = probs.numpy()  <span class="comment"># 将概率转换为 NumPy 数组</span></span><br><span class="line">        single_video_result[keyword] = texts[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]]  <span class="comment"># 选择具有最高概率的词汇作为结果</span></span><br><span class="line">        </span><br><span class="line">    submit_json[<span class="string">&quot;test_results&quot;</span>].append(single_video_result)  <span class="comment"># 将结果添加到测试结果列表</span></span><br><span class="line">    </span><br><span class="line"><span class="comment"># 将最终结果写入 JSON 文件</span></span><br><span class="line"><span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">&#x27;clip_result.json&#x27;</span>, <span class="string">&#x27;w&#x27;</span>, encoding=<span class="string">&#x27;utf-8&#x27;</span>) <span class="keyword">as</span> up:</span><br><span class="line">    json.dump(submit_json, up, ensure_ascii=<span class="literal">False</span>)  <span class="comment"># 以 UTF-8 编码将结果保存到文件中</span></span><br></pre></td></tr></table></figure>
<h3 id="进阶思路"><a href="#进阶思路" class="headerlink" title="进阶思路"></a>进阶思路</h3><ul>
<li>使用图像进行视觉问答</li>
<li>时序视频进行视频问答</li>
<li>使用多模态大模型（CLIP）进行问答</li>
</ul>
<h4 id="多模态大模型CLIP简介"><a href="#多模态大模型CLIP简介" class="headerlink" title="多模态大模型CLIP简介"></a>多模态大模型CLIP简介</h4><p>CLIP（Contrastive Language-Image Pre-training）是一种多模态大模型，由OpenAI开发。它是一种能够同时理解文本和图像的模型，通过对文本和图像进行对比性学习，使其在多模态任务上表现出色。以下是CLIP的一些关键特点和工作原理的简介：</p>
<ol>
<li><strong>多模态表示学习：</strong> CLIP的设计目标是使模型能够理解文本和图像之间的语义关系，而不是仅限于特定任务。这使得CLIP在各种任务上都能表现良好，而无需针对每个任务进行专门的微调。</li>
<li><strong>对比性学习：</strong> CLIP使用对比损失进行训练。这意味着模型学会将相关的文本和图像样本靠近，而不相关的样本分开。这种对比性学习的方法使得CLIP在理解语义关系时更为强大。</li>
<li><strong>零样本学习：</strong> CLIP在零样本学习方面表现出色。这意味着模型可以在没有特定任务样本的情况下执行任务，因为它已经学会了通用的文本-图像表示。</li>
<li><strong>大规模预训练：</strong> CLIP是在大规模文本和图像数据上进行预训练的。这使得模型能够捕捉更广泛的语义信息，从而在多种任务上通用。</li>
<li><strong>应用广泛：</strong> 由于其多模态的性质，CLIP可以用于多种任务，包括图像分类、物体检测、文本检索等。</li>
</ol>
<p>总体而言，CLIP代表了一种强大的多模态学习方法，使得模型能够理解文本和图像之间的语义关系，并在各种任务上表现出色。</p>
<h3 id="大佬代码解读"><a href="#大佬代码解读" class="headerlink" title="大佬代码解读"></a>大佬代码解读</h3><p>大佬代码地址（大家可以关注膜拜一下大佬）：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.kaggle.com/code/peilwang/self-drive">self drive | Kaggle</a></p>
<h4 id="推理天气，时间和道路结构"><a href="#推理天气，时间和道路结构" class="headerlink" title="推理天气，时间和道路结构"></a>推理天气，时间和道路结构</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 导入必要的库</span></span><br><span class="line"><span class="keyword">import</span> glob</span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建一个JSON格式的字典，包含作者信息、时间戳、模型名称和一个空的测试结果列表</span></span><br><span class="line">submit_json = &#123;</span><br><span class="line">    <span class="string">&quot;author&quot;</span> : <span class="string">&quot;abc&quot;</span> ,</span><br><span class="line">    <span class="string">&quot;time&quot;</span> : <span class="string">&quot;231011&quot;</span>,</span><br><span class="line">    <span class="string">&quot;model&quot;</span> : <span class="string">&quot;model_name&quot;</span>,</span><br><span class="line">    <span class="string">&quot;test_results&quot;</span> : []</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取指定路径下的视频文件列表，排序后存储在paths变量中</span></span><br><span class="line">paths = glob.glob(<span class="string">&#x27;/kaggle/input/clip-test/初赛测试视频/*&#x27;</span>)</span><br><span class="line">paths.sort()</span><br><span class="line">debug = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果设置了debug标志，则只选择一个特定的视频路径用于调试</span></span><br><span class="line"><span class="keyword">if</span> debug:</span><br><span class="line">    paths = [<span class="string">&#x27;/kaggle/input/clip-test/初赛测试视频/40.avi&#x27;</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 遍历每个视频文件</span></span><br><span class="line"><span class="keyword">for</span> video_path <span class="keyword">in</span> paths:</span><br><span class="line">    <span class="built_in">print</span>(video_path)</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 提取视频文件名作为clip_id</span></span><br><span class="line">    clip_id = video_path.split(<span class="string">&#x27;/&#x27;</span>)[-<span class="number">1</span>]</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 打开视频文件</span></span><br><span class="line">    cap = cv2.VideoCapture(video_path)</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 读取视频的第一帧图像</span></span><br><span class="line">    img = cap.read()[<span class="number">1</span>]</span><br><span class="line">    img = cap.read()[<span class="number">1</span>]</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 获取图像的高度、宽度和通道数</span></span><br><span class="line">    height, width, _ = img.shape</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 截取图像的上部分，保留下部分的 75%</span></span><br><span class="line">    end_row = <span class="built_in">int</span>(height * <span class="number">0.75</span>)</span><br><span class="line">    img2 = img[<span class="number">0</span>:end_row, :]</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 对图像进行预处理，转换为模型所需的格式</span></span><br><span class="line">    image1 = preprocess(Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))).unsqueeze(<span class="number">0</span>).to(device)</span><br><span class="line">    image2 = preprocess(Image.fromarray(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))).unsqueeze(<span class="number">0</span>).to(device)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 创建包含初始信息的单个视频结果字典</span></span><br><span class="line">    single_video_result = &#123;</span><br><span class="line">        <span class="string">&quot;clip_id&quot;</span>: clip_id,</span><br><span class="line">        <span class="string">&quot;scerario&quot;</span> : <span class="string">&quot;city street&quot;</span>,</span><br><span class="line">        <span class="string">&quot;weather&quot;</span>:<span class="string">&quot;clear&quot;</span>,</span><br><span class="line">        <span class="string">&quot;period&quot;</span>:<span class="string">&quot;night&quot;</span>,</span><br><span class="line">        <span class="string">&quot;road_structure&quot;</span>:<span class="string">&quot;normal&quot;</span>,</span><br><span class="line">        <span class="string">&quot;general_obstacle&quot;</span>:<span class="string">&quot;nothing&quot;</span>,</span><br><span class="line">        <span class="string">&quot;abnormal_condition&quot;</span>:<span class="string">&quot;nothing&quot;</span>,</span><br><span class="line">        <span class="string">&quot;ego_car_behavior&quot;</span>:<span class="string">&quot;go straight&quot;</span>,</span><br><span class="line">        <span class="string">&quot;closest_participants_type&quot;</span>:<span class="string">&quot;passenger car&quot;</span>,</span><br><span class="line">        <span class="string">&quot;closest_participants_behavior&quot;</span>:<span class="string">&quot;braking&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 遍历关键词（en_match_words中的关键词）</span></span><br><span class="line">    <span class="keyword">for</span> keyword <span class="keyword">in</span> en_match_words.keys():</span><br><span class="line">        <span class="comment"># 如果关键词不是[&quot;weather&quot;, &quot;period&quot;, &quot;road_structure&quot;]中的一个，跳过</span></span><br><span class="line">        <span class="keyword">if</span> keyword <span class="keyword">not</span> <span class="keyword">in</span> [<span class="string">&quot;weather&quot;</span>, <span class="string">&quot;period&quot;</span>, <span class="string">&quot;road_structure&quot;</span>]:</span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">            </span><br><span class="line">        <span class="comment"># 获取关键词对应的文本列表</span></span><br><span class="line">        texts = np.array(en_match_words[keyword])</span><br><span class="line">        text = clip.tokenize(texts).to(device)</span><br><span class="line">        </span><br><span class="line">        <span class="comment"># 使用torch.no_grad()上下文，避免计算梯度</span></span><br><span class="line">        <span class="keyword">with</span> torch.no_grad():</span><br><span class="line">            <span class="keyword">if</span> keyword == <span class="string">&#x27;period&#x27;</span>:</span><br><span class="line">                <span class="comment"># 检查关键词是否为 &#x27;period&#x27;</span></span><br><span class="line">                <span class="comment"># 对于关键词 &#x27;period&#x27;，根据模型预测白天或夜晚</span></span><br><span class="line">                height, width, _ = img.shape</span><br><span class="line">                end_row = <span class="built_in">int</span>(height * <span class="number">0.5</span>)</span><br><span class="line">                img_day = img[<span class="number">0</span>:end_row, :]</span><br><span class="line">                img_day = preprocess(Image.fromarray(cv2.cvtColor(img_day, cv2.COLOR_BGR2RGB))).unsqueeze(<span class="number">0</span>).to(device)</span><br><span class="line">                <span class="comment"># 预处理 &#x27;period&#x27; 关键词的图像</span></span><br><span class="line">                logits_per_image, logits_per_text = model(img_day, text)</span><br><span class="line">                <span class="comment"># 获取模型预测结果</span></span><br><span class="line">                probs = logits_per_image.softmax(dim=-<span class="number">1</span>).cpu().numpy()</span><br><span class="line">                <span class="comment"># 将预测转换为概率</span></span><br><span class="line">                <span class="keyword">if</span> probs[<span class="number">0</span>][<span class="number">0</span>] &lt; <span class="number">0.85</span>:</span><br><span class="line">                    <span class="comment"># 如果是 &#x27;daytime&#x27; 的概率小于 0.85，则分类为 &#x27;night&#x27;</span></span><br><span class="line">                    single_video_result[keyword] = <span class="string">&#x27;night&#x27;</span></span><br><span class="line">                <span class="keyword">else</span>:</span><br><span class="line">                    <span class="comment"># 否则分类为 &#x27;daytime&#x27;</span></span><br><span class="line">                    single_video_result[keyword] = <span class="string">&#x27;daytime&#x27;</span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">else</span>:</span><br><span class="line">                <span class="comment"># 对于其他关键词，根据模型预测关键词的可能类别，并选择概率最高的类别作为结果</span></span><br><span class="line">                <span class="comment"># 使用两个不同的图像进行模型预测</span></span><br><span class="line">                logits_per_image1, logits_per_text1 = model(image1, text)</span><br><span class="line">                logits_per_image2, logits_per_text2 = model(image2, text)</span><br><span class="line">                <span class="comment"># 从两个预测中获取预测结果</span></span><br><span class="line">                probs1 = logits_per_image1.softmax(dim=-<span class="number">1</span>).cpu().numpy()</span><br><span class="line">                probs2 = logits_per_image2.softmax(dim=-<span class="number">1</span>).cpu().numpy()</span><br><span class="line">                <span class="comment"># 将两个预测的概率进行组合</span></span><br><span class="line">                probs = probs1 + probs2</span><br><span class="line">                <span class="comment"># 选择概率最高的类别作为结果</span></span><br><span class="line">                single_video_result[keyword] = texts[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]]</span><br><span class="line">            </span><br><span class="line">            <span class="comment"># 如果关键词为 &quot;parking lot entrance&quot;</span></span><br><span class="line">            <span class="keyword">if</span> texts[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]] == <span class="string">&quot;parking lot entrance&quot;</span>:</span><br><span class="line">                <span class="comment"># 再次使用模型预测其他可能的条件</span></span><br><span class="line">                texts = [<span class="string">&quot;uneven&quot;</span>,<span class="string">&quot;水渍&quot;</span>,<span class="string">&quot;油渍&quot;</span>,<span class="string">&quot;积水&quot;</span>,<span class="string">&quot;cracked&quot;</span>]</span><br><span class="line">                text = clip.tokenize(texts).to(device)</span><br><span class="line">                logits_per_image1, logits_per_text1 = model(image2, text)</span><br><span class="line">                probs = logits_per_image1.softmax(dim=-<span class="number">1</span>).cpu().numpy()</span><br><span class="line">                <span class="comment"># 根据概率值确定结果</span></span><br><span class="line">                <span class="keyword">if</span> texts[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]] <span class="keyword">in</span> [<span class="string">&quot;水渍&quot;</span>,<span class="string">&quot;油渍&quot;</span>]:</span><br><span class="line">                    single_video_result[<span class="string">&#x27;abnormal_condition&#x27;</span>] = <span class="string">&quot;oil or water stain&quot;</span></span><br><span class="line">                <span class="keyword">elif</span> texts[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]] == <span class="string">&#x27;积水&#x27;</span>:</span><br><span class="line">                    single_video_result[<span class="string">&#x27;abnormal_condition&#x27;</span>] = <span class="string">&quot;standing water&quot;</span></span><br><span class="line">                <span class="keyword">else</span> :</span><br><span class="line">                    single_video_result[<span class="string">&#x27;abnormal_condition&#x27;</span>] = texts[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]]</span><br><span class="line">                <span class="built_in">print</span>(single_video_result[<span class="string">&#x27;abnormal_condition&#x27;</span>])</span><br><span class="line">                </span><br><span class="line">    <span class="comment"># 调整特定的 &quot;road_structure&quot; 值</span></span><br><span class="line">    <span class="keyword">if</span> single_video_result[<span class="string">&quot;road_structure&quot;</span>] == <span class="string">&quot;Ordinary roads&quot;</span>:</span><br><span class="line">        single_video_result[<span class="string">&quot;road_structure&quot;</span>] = <span class="string">&quot;normal&quot;</span></span><br><span class="line">    <span class="keyword">if</span> single_video_result[<span class="string">&quot;road_structure&quot;</span>] == <span class="string">&#x27;lane merging&#x27;</span>:</span><br><span class="line">        <span class="comment"># 如果 &quot;road_structure&quot; 为 &#x27;lane merging&#x27;，再次使用模型预测并调整结果</span></span><br><span class="line">        texts = np.array([<span class="string">&#x27;车道合并&#x27;</span>,<span class="string">&#x27;普通道路&#x27;</span>])</span><br><span class="line">        text = clip.tokenize(texts).to(device)</span><br><span class="line">        logits_per_image1, logits_per_text1 = model(image1, text)</span><br><span class="line">        probs1 = logits_per_image1.softmax(dim=-<span class="number">1</span>).cpu().detach().numpy()</span><br><span class="line">        <span class="keyword">if</span> texts[probs1[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]] != <span class="string">&#x27;车道合并&#x27;</span>:</span><br><span class="line">            single_video_result[<span class="string">&quot;road_structure&quot;</span>] = <span class="string">&#x27;normal&#x27;</span></span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 将单个视频结果添加到submit_json中的测试结果列表</span></span><br><span class="line">    submit_json[<span class="string">&quot;test_results&quot;</span>].append(single_video_result)</span><br></pre></td></tr></table></figure>
<h4 id="推理最近交通参与者"><a href="#推理最近交通参与者" class="headerlink" title="推理最近交通参与者"></a>推理最近交通参与者</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 导入必要的库</span></span><br><span class="line"><span class="keyword">import</span> glob</span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"></span><br><span class="line"><span class="comment"># 初始化一个 JSON 格式的字典，用于存储视频结果</span></span><br><span class="line">submit_json_video = &#123;</span><br><span class="line">    <span class="string">&quot;author&quot;</span>: <span class="string">&quot;abc&quot;</span>,</span><br><span class="line">    <span class="string">&quot;time&quot;</span>: <span class="string">&quot;231011&quot;</span>,</span><br><span class="line">    <span class="string">&quot;model&quot;</span>: <span class="string">&quot;model_name&quot;</span>,</span><br><span class="line">    <span class="string">&quot;test_results&quot;</span>: []</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义包含不同场景关键词可能取值的字典</span></span><br><span class="line">en_match_words = &#123;</span><br><span class="line">    <span class="string">&quot;scerario&quot;</span>: [<span class="string">&quot;suburbs&quot;</span>, <span class="string">&quot;city street&quot;</span>, <span class="string">&quot;expressway&quot;</span>, <span class="string">&quot;tunnel&quot;</span>, <span class="string">&quot;parking-lot&quot;</span>, <span class="string">&quot;gas or charging stations&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;weather&quot;</span>: [<span class="string">&quot;clear&quot;</span>, <span class="string">&quot;cloudy&quot;</span>, <span class="string">&quot;raining&quot;</span>, <span class="string">&quot;foggy&quot;</span>, <span class="string">&quot;snowying&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;period&quot;</span>: [<span class="string">&quot;daytime&quot;</span>, <span class="string">&quot;dawn or dusk&quot;</span>, <span class="string">&quot;night&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;road_structure&quot;</span>: [<span class="string">&quot;Ordinary roads&quot;</span>, <span class="string">&quot;crossroads&quot;</span>, <span class="string">&quot;T-junction&quot;</span>, <span class="string">&quot;ramp&quot;</span>, <span class="string">&quot;lane merging&quot;</span>, <span class="string">&quot;parking lot entrance&quot;</span>, <span class="string">&quot;round about&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;general_obstacle&quot;</span>: [<span class="string">&quot;nothing&quot;</span>, <span class="string">&quot;speed bumper&quot;</span>, <span class="string">&quot;traffic cone&quot;</span>, <span class="string">&quot;water horse&quot;</span>, <span class="string">&quot;stone&quot;</span>, <span class="string">&quot;manhole cover&quot;</span>, <span class="string">&quot;nothing&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;abnormal_condition&quot;</span>: [<span class="string">&quot;uneven&quot;</span>, <span class="string">&quot;oil or water stain&quot;</span>, <span class="string">&quot;standing water&quot;</span>, <span class="string">&quot;cracked&quot;</span>, <span class="string">&quot;nothing&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;ego_car_behavior&quot;</span>: [<span class="string">&quot;slow down&quot;</span>, <span class="string">&quot;go straight&quot;</span>, <span class="string">&quot;turn right&quot;</span>, <span class="string">&quot;turn left&quot;</span>, <span class="string">&quot;stop&quot;</span>, <span class="string">&quot;U-turn&quot;</span>, <span class="string">&quot;speed up&quot;</span>, <span class="string">&quot;lane change&quot;</span>, <span class="string">&quot;others&quot;</span>],</span><br><span class="line">    <span class="string">&quot;closest_participants_type&quot;</span>: [<span class="string">&quot;normal car&quot;</span>, <span class="string">&quot;bus&quot;</span>, <span class="string">&quot;truck&quot;</span>, <span class="string">&quot;people&quot;</span>, <span class="string">&quot;police&quot;</span>, <span class="string">&quot;nothing&quot;</span>, <span class="string">&quot;others&quot;</span>, <span class="string">&quot;unknown&quot;</span>],</span><br><span class="line">    <span class="string">&quot;closest_participants_behavior&quot;</span>: [<span class="string">&quot;slow down&quot;</span>, <span class="string">&quot;go straight&quot;</span>, <span class="string">&quot;turn right&quot;</span>, <span class="string">&quot;turn left&quot;</span>, <span class="string">&quot;stop&quot;</span>, <span class="string">&quot;U-turn&quot;</span>, <span class="string">&quot;speed up&quot;</span>, <span class="string">&quot;lane change&quot;</span>, <span class="string">&quot;others&quot;</span>],</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取视频文件的路径并进行排序</span></span><br><span class="line">paths = glob.glob(<span class="string">&#x27;/kaggle/input/clip-test/初赛测试视频/*&#x27;</span>)</span><br><span class="line">paths.sort()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定用于分析的关键词（例如，[&#x27;closest_participants_type&#x27;]）</span></span><br><span class="line">keys = [<span class="string">&#x27;closest_participants_type&#x27;</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置调试标志，以控制是处理所有视频还是只处理特定视频</span></span><br><span class="line">debug = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果处于调试模式，则使用特定的视频进行测试</span></span><br><span class="line"><span class="keyword">if</span> debug:</span><br><span class="line">    paths = [<span class="string">&#x27;/kaggle/input/clip-test/初赛测试视频/45.avi&#x27;</span>]</span><br><span class="line">    </span><br><span class="line"><span class="comment"># 遍历每个视频路径</span></span><br><span class="line"><span class="keyword">for</span> video_path <span class="keyword">in</span> paths:</span><br><span class="line">    <span class="built_in">print</span>(video_path)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 初始化一个数组，用于存储每个关键词的概率总和</span></span><br><span class="line">    ans = [[<span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">0</span>]]</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 提取视频文件名作为 clip_id</span></span><br><span class="line">    clip_id = video_path.split(<span class="string">&#x27;/&#x27;</span>)[-<span class="number">1</span>]</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 打开视频文件</span></span><br><span class="line">    cap = cv2.VideoCapture(video_path)</span><br><span class="line">    fps = cap.get(cv2.CAP_PROP_FPS)</span><br><span class="line">    frame_count = <span class="built_in">int</span>(cap.get(cv2.CAP_PROP_FRAME_COUNT))</span><br><span class="line"></span><br><span class="line">    results = []</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 定义用于帧采样率的变量 &#x27;x&#x27;</span></span><br><span class="line">    x = <span class="number">5</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 以基于 &#x27;x&#x27; 的采样率遍历帧</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, frame_count, <span class="built_in">int</span>(fps // x)):</span><br><span class="line">        <span class="comment"># 将帧位置设置为当前索引</span></span><br><span class="line">        cap.<span class="built_in">set</span>(cv2.CAP_PROP_POS_FRAMES, i)</span><br><span class="line">        ret, img = cap.read()</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 如果帧读取不成功，则中断循环</span></span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> ret:</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line"></span><br><span class="line">        <span class="comment"># 从帧底部提取感兴趣区域（ROI）</span></span><br><span class="line">        height, width, _ = img.shape</span><br><span class="line">        start_row = <span class="built_in">int</span>(height * <span class="number">0</span>)</span><br><span class="line">        img = img[start_row:height, :]</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 对帧图像进行预处理</span></span><br><span class="line">        image = preprocess(Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))).unsqueeze(<span class="number">0</span>).to(device)</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 初始化一个用于单帧结果的字典</span></span><br><span class="line">        single_frame_result = &#123;</span><br><span class="line">            <span class="string">&quot;clip_id&quot;</span>: clip_id,</span><br><span class="line">            <span class="string">&quot;scerario&quot;</span>: <span class="string">&quot;city street&quot;</span>,</span><br><span class="line">            <span class="string">&quot;weather&quot;</span>: <span class="string">&quot;clear&quot;</span>,</span><br><span class="line">            <span class="string">&quot;period&quot;</span>: <span class="string">&quot;night&quot;</span>,</span><br><span class="line">            <span class="string">&quot;road_structure&quot;</span>: <span class="string">&quot;normal&quot;</span>,</span><br><span class="line">            <span class="string">&quot;general_obstacle&quot;</span>: <span class="string">&quot;nothing&quot;</span>,</span><br><span class="line">            <span class="string">&quot;abnormal_condition&quot;</span>: <span class="string">&quot;nothing&quot;</span>,</span><br><span class="line">            <span class="string">&quot;ego_car_behavior&quot;</span>: <span class="string">&quot;go straight&quot;</span>,</span><br><span class="line">            <span class="string">&quot;closest_participants_type&quot;</span>: <span class="string">&quot;passenger car&quot;</span>,</span><br><span class="line">            <span class="string">&quot;closest_participants_behavior&quot;</span>: <span class="string">&quot;braking&quot;</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 遍历指定的关键词（例如，[&#x27;closest_participants_type&#x27;]）</span></span><br><span class="line">        <span class="keyword">for</span> k, keyword <span class="keyword">in</span> <span class="built_in">enumerate</span>(keys):</span><br><span class="line">            <span class="comment"># 对于特定帧跳过处理 &#x27;closest_participants_type&#x27;</span></span><br><span class="line">            <span class="keyword">if</span> keyword == <span class="string">&quot;closest_participants_type&quot;</span> <span class="keyword">and</span> (i &lt; fps * <span class="number">5</span> // x <span class="keyword">or</span> i &gt; fps * <span class="number">7</span> // x):</span><br><span class="line">                <span class="keyword">continue</span></span><br><span class="line"></span><br><span class="line">            <span class="comment"># 获取关键词对应的文本</span></span><br><span class="line">            texts = np.array(en_match_words[keyword])</span><br><span class="line">            text = clip.tokenize(texts).to(device)</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 使用无梯度计算推理结果</span></span><br><span class="line">            <span class="keyword">with</span> torch.no_grad():</span><br><span class="line">                logits_per_image, logits_per_text = model(image, text)</span><br><span class="line">                probs = logits_per_image.softmax(dim=-<span class="number">1</span>).cpu().numpy()</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 将概率累加到 ans 数组中</span></span><br><span class="line">            <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ans[k])):</span><br><span class="line">                ans[k][j] += probs[<span class="number">0</span>][j]</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 对 ans 数组中的每个关键词，选择具有最大概率的文本值</span></span><br><span class="line">    <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(ans)):</span><br><span class="line">        single_frame_result[keys[i]] = en_match_words[keys[i]][ans[i].index((<span class="built_in">max</span>(ans[i])))]</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 将单帧结果添加到 JSON 结果列表中</span></span><br><span class="line">    submit_json_video[<span class="string">&quot;test_results&quot;</span>].append(single_frame_result)</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 释放视频文件资源</span></span><br><span class="line">    cap.release()</span><br></pre></td></tr></table></figure>
<h4 id="推理自车行为"><a href="#推理自车行为" class="headerlink" title="推理自车行为"></a>推理自车行为</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> glob</span><br><span class="line"><span class="keyword">import</span> pandas <span class="keyword">as</span> pd</span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="keyword">import</span> gc</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="keyword">import</span> imageio</span><br><span class="line"><span class="keyword">import</span> tensorflow <span class="keyword">as</span> tf</span><br><span class="line"><span class="keyword">from</span> sklearn.model_selection <span class="keyword">import</span> train_test_split</span><br><span class="line"><span class="keyword">from</span> tqdm.notebook <span class="keyword">import</span> tqdm</span><br><span class="line"><span class="keyword">from</span> tensorflow_docs.vis <span class="keyword">import</span> embed</span><br><span class="line"><span class="keyword">import</span> matplotlib.pyplot <span class="keyword">as</span> plt</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">format_frames</span>(<span class="params">frame, output_size</span>):</span><br><span class="line">  <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    Pad and resize an image from a video.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Args:</span></span><br><span class="line"><span class="string">      frame: Image that needs to resized and padded. </span></span><br><span class="line"><span class="string">      output_size: Pixel size of the output frame image.</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    Return:</span></span><br><span class="line"><span class="string">      Formatted frame with padding of specified output size.</span></span><br><span class="line"><span class="string">  &quot;&quot;&quot;</span></span><br><span class="line">    frame = tf.image.convert_image_dtype(frame, tf.float32)</span><br><span class="line">    frame = tf.image.resize_with_pad(frame, *output_size)</span><br><span class="line">    <span class="keyword">return</span> frame</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义一个函数，用于从视频文件中提取帧序列</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">frames_from_video_file</span>(<span class="params">video_path, n_frames, output_size=(<span class="params"><span class="number">224</span>, <span class="number">224</span></span>), frame_step=<span class="number">15</span></span>):</span><br><span class="line">    <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">    从每个视频文件中创建帧序列。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    参数：</span></span><br><span class="line"><span class="string">      video_path：视频文件的文件路径。</span></span><br><span class="line"><span class="string">      n_frames：要从每个视频文件中创建的帧数。</span></span><br><span class="line"><span class="string">      output_size：输出帧图像的像素大小。</span></span><br><span class="line"><span class="string">      frame_step：帧步长，即每隔多少帧采样一次。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">    返回：</span></span><br><span class="line"><span class="string">      一个形状为 (n_frames, height, width, channels) 的 NumPy 数组，包含从视频文件中提取的帧。</span></span><br><span class="line"><span class="string">    &quot;&quot;&quot;</span></span><br><span class="line">    <span class="comment"># 读取每个视频的每一帧</span></span><br><span class="line">    result = []</span><br><span class="line">    src = cv2.VideoCapture(<span class="built_in">str</span>(video_path))  <span class="comment"># 打开视频文件</span></span><br><span class="line"></span><br><span class="line">    video_length = src.get(cv2.CAP_PROP_FRAME_COUNT)  <span class="comment"># 获取视频的总帧数</span></span><br><span class="line"></span><br><span class="line">    need_length = <span class="number">1</span> + (n_frames - <span class="number">1</span>) * frame_step  <span class="comment"># 计算需要的帧序列长度</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 根据视频长度和需要的长度计算起始帧的位置</span></span><br><span class="line">    <span class="keyword">if</span> need_length &gt; video_length:</span><br><span class="line">        start = <span class="number">0</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        max_start = video_length - need_length</span><br><span class="line">        start = random.randint(<span class="number">0</span>, max_start + <span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">    src.<span class="built_in">set</span>(cv2.CAP_PROP_POS_FRAMES, start)  <span class="comment"># 设置视频的起始帧位置</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 读取第一帧</span></span><br><span class="line">    ret, frame = src.read()</span><br><span class="line">    result.append(format_frames(frame, output_size))  <span class="comment"># 将第一帧添加到结果列表</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 循环读取后续帧</span></span><br><span class="line">    <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(n_frames - <span class="number">1</span>):</span><br><span class="line">        <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(frame_step):</span><br><span class="line">            ret, frame = src.read()</span><br><span class="line">        <span class="keyword">if</span> ret:</span><br><span class="line">            frame = format_frames(frame, output_size)</span><br><span class="line">            result.append(frame)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            result.append(np.zeros_like(result[<span class="number">0</span>]))  <span class="comment"># 如果视频读取失败，用零填充</span></span><br><span class="line"></span><br><span class="line">    src.release()  <span class="comment"># 释放视频资源</span></span><br><span class="line">    result = np.array(result)[..., [<span class="number">2</span>, <span class="number">1</span>, <span class="number">0</span>]]  <span class="comment"># 将结果转换为 NumPy 数组，并重新排序通道顺序（BGR 到 RGB）</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> result</span><br><span class="line"></span><br><span class="line"><span class="comment"># 定义一个函数，将图像序列保存为 GIF 文件并返回嵌入的文件链接</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">to_gif</span>(<span class="params">images</span>):</span><br><span class="line">    converted_images = np.clip(images * <span class="number">255</span>, <span class="number">0</span>, <span class="number">255</span>).astype(np.uint8)  <span class="comment"># 将图像值从 [0, 1] 转换为 [0, 255] 并转为整数</span></span><br><span class="line">    imageio.mimsave(<span class="string">&#x27;./animation.gif&#x27;</span>, converted_images, fps=<span class="number">10</span>)  <span class="comment"># 保存为 GIF 文件</span></span><br><span class="line">    <span class="keyword">return</span> embed.embed_file(<span class="string">&#x27;./animation.gif&#x27;</span>)  <span class="comment"># 返回嵌入的文件链接</span></span><br></pre></td></tr></table></figure>
<h4 id="推理场景"><a href="#推理场景" class="headerlink" title="推理场景"></a>推理场景</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> torch.utils.data <span class="keyword">import</span> DataLoader, Dataset</span><br><span class="line"><span class="keyword">import</span> os</span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">CustomDataset</span>(<span class="title class_ inherited__">Dataset</span>):</span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__init__</span>(<span class="params">self, preprocess, image_files, transform=<span class="literal">None</span></span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        自定义数据集类的初始化函数。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        参数：</span></span><br><span class="line"><span class="string">          preprocess：图像预处理函数。</span></span><br><span class="line"><span class="string">          image_files：包含图像文件路径的列表。</span></span><br><span class="line"><span class="string">          transform：可选的图像转换函数。</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        self.image_files = image_files</span><br><span class="line">        self.transform = transform</span><br><span class="line">        self.preprocess = preprocess</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__len__</span>(<span class="params">self</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        获取数据集的长度。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        返回：</span></span><br><span class="line"><span class="string">          数据集的长度。</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        <span class="keyword">return</span> <span class="built_in">len</span>(self.image_files)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">def</span> <span class="title function_">__getitem__</span>(<span class="params">self, i</span>):</span><br><span class="line">        <span class="string">&quot;&quot;&quot;</span></span><br><span class="line"><span class="string">        获取数据集中索引为 i 的样本。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        参数：</span></span><br><span class="line"><span class="string">          i：样本的索引。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        返回：</span></span><br><span class="line"><span class="string">          clip_images：视频片段帧的预处理结果列表。</span></span><br><span class="line"><span class="string">          images：视频片段帧的原始图像列表。</span></span><br><span class="line"><span class="string">          filename：图像文件的基本文件名。</span></span><br><span class="line"><span class="string">        &quot;&quot;&quot;</span></span><br><span class="line">        cap = cv2.VideoCapture(self.image_files[i])  <span class="comment"># 打开视频文件</span></span><br><span class="line">        fps = cap.get(cv2.CAP_PROP_FPS)  <span class="comment"># 获取视频的帧率</span></span><br><span class="line">        frame_count = <span class="built_in">int</span>(cap.get(cv2.CAP_PROP_FRAME_COUNT))  <span class="comment"># 获取视频的帧数</span></span><br><span class="line">        images = []  <span class="comment"># 存储原始图像列表</span></span><br><span class="line">        clip_images = []  <span class="comment"># 存储预处理后的图像列表</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>, frame_count, <span class="built_in">int</span>(fps // <span class="number">1</span>)):  <span class="comment"># 以指定帧率采样视频帧</span></span><br><span class="line">            cap.<span class="built_in">set</span>(cv2.CAP_PROP_POS_FRAMES, j)  <span class="comment"># 设置当前帧位置</span></span><br><span class="line">            ret, img = cap.read()  <span class="comment"># 读取当前帧</span></span><br><span class="line"></span><br><span class="line">            height, width, _ = img.shape</span><br><span class="line">            start_row = <span class="built_in">int</span>(height * <span class="number">0.20</span>)</span><br><span class="line">            img = img[start_row:height, :]</span><br><span class="line">            img = cv2.fastNlMeansDenoisingColored(img, <span class="literal">None</span>, <span class="number">10</span>, <span class="number">10</span>, <span class="number">7</span>, <span class="number">21</span>)  <span class="comment"># 对图像进行去噪处理</span></span><br><span class="line"></span><br><span class="line">            clip_images.append(self.preprocess(Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))).unsqueeze(<span class="number">0</span>))</span><br><span class="line">            img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))</span><br><span class="line"></span><br><span class="line">            image = np.array(img.convert(<span class="string">&#x27;RGB&#x27;</span>))</span><br><span class="line"></span><br><span class="line">            <span class="keyword">if</span> self.transform <span class="keyword">is</span> <span class="keyword">not</span> <span class="literal">None</span>:</span><br><span class="line">                image = self.transform(image=image)[<span class="string">&#x27;image&#x27;</span>]</span><br><span class="line">            images.append(image)</span><br><span class="line"></span><br><span class="line">        cap.release()  <span class="comment"># 释放视频资源</span></span><br><span class="line">        <span class="keyword">return</span> clip_images, images, os.path.basename(self.image_files[i])  <span class="comment"># 返回视频片段帧的预处理结果列表、原始图像列表和文件名</span></span><br></pre></td></tr></table></figure>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> glob</span><br><span class="line"><span class="keyword">import</span> cv2</span><br><span class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</span><br><span class="line"><span class="keyword">import</span> clip</span><br><span class="line"><span class="keyword">import</span> torch</span><br><span class="line"><span class="keyword">import</span> torchvision.models <span class="keyword">as</span> models</span><br><span class="line"><span class="keyword">from</span> PIL <span class="keyword">import</span> Image</span><br><span class="line"></span><br><span class="line"><span class="comment"># 初始化存放测试结果的字典</span></span><br><span class="line">submit_json_scerario = &#123;</span><br><span class="line">    <span class="string">&quot;author&quot;</span> : <span class="string">&quot;abc&quot;</span> ,</span><br><span class="line">    <span class="string">&quot;time&quot;</span> : <span class="string">&quot;231011&quot;</span>,</span><br><span class="line">    <span class="string">&quot;model&quot;</span> : <span class="string">&quot;model_name&quot;</span>,</span><br><span class="line">    <span class="string">&quot;test_results&quot;</span> : []</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment"># 获取所有视频文件的路径</span></span><br><span class="line">paths = glob.glob(<span class="string">&#x27;/kaggle/input/clip-test/初赛测试视频/*&#x27;</span>)</span><br><span class="line">paths.sort()</span><br><span class="line">debug = <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 如果处于调试模式，只选择一个视频进行处理</span></span><br><span class="line"><span class="keyword">if</span> debug:</span><br><span class="line">    paths = [<span class="string">&#x27;/kaggle/input/clip-test/初赛测试视频/03.avi&#x27;</span>]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建自定义数据集</span></span><br><span class="line">datasets = CustomDataset(preprocess, paths)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 创建数据加载器</span></span><br><span class="line">dataloaders = DataLoader(datasets, batch_size=<span class="number">1</span>, num_workers=<span class="number">2</span>, pin_memory=<span class="literal">True</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 遍历数据加载器中的每个视频</span></span><br><span class="line"><span class="keyword">for</span> clip_images, datas, clip_id <span class="keyword">in</span> dataloaders:</span><br><span class="line">    <span class="comment"># 初始化单个视频的测试结果字典</span></span><br><span class="line">    single_frame_result = &#123;</span><br><span class="line">        <span class="string">&quot;clip_id&quot;</span>: clip_id,</span><br><span class="line">        <span class="string">&quot;scerario&quot;</span> : <span class="string">&quot;city street&quot;</span>,</span><br><span class="line">        <span class="string">&quot;weather&quot;</span>: <span class="string">&quot;clear&quot;</span>,</span><br><span class="line">        <span class="string">&quot;period&quot;</span>: <span class="string">&quot;night&quot;</span>,</span><br><span class="line">        <span class="string">&quot;road_structure&quot;</span>: <span class="string">&quot;normal&quot;</span>,</span><br><span class="line">        <span class="string">&quot;general_obstacle&quot;</span>: <span class="string">&quot;nothing&quot;</span>,</span><br><span class="line">        <span class="string">&quot;abnormal_condition&quot;</span>: <span class="string">&quot;nothing&quot;</span>,</span><br><span class="line">        <span class="string">&quot;ego_car_behavior&quot;</span>: <span class="string">&quot;go straight&quot;</span>,</span><br><span class="line">        <span class="string">&quot;closest_participants_type&quot;</span>: <span class="string">&quot;passenger car&quot;</span>,</span><br><span class="line">        <span class="string">&quot;closest_participants_behavior&quot;</span>: <span class="string">&quot;braking&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">print</span>(clip_id)</span><br><span class="line">    </span><br><span class="line">    <span class="comment"># 初始化用于存放场景类别统计的列表</span></span><br><span class="line">    clip_ans = [<span class="number">0</span> <span class="keyword">for</span> x <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(scerario_clip))]</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 遍历视频的每一帧</span></span><br><span class="line">    <span class="keyword">for</span> i, data <span class="keyword">in</span> <span class="built_in">enumerate</span>(clip_images):</span><br><span class="line">        texts = np.array(scerario_clip)</span><br><span class="line">        text = clip.tokenize(texts).to(device)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">with</span> torch.no_grad():</span><br><span class="line">            <span class="comment"># 使用模型进行推理</span></span><br><span class="line">            logits_per_image, logits_per_text = model(data.squeeze(<span class="number">0</span>).to(device), text)</span><br><span class="line">            probs = logits_per_image.softmax(dim=-<span class="number">1</span>).cpu().numpy()</span><br><span class="line"></span><br><span class="line">            <span class="comment"># 统计场景类别的数量</span></span><br><span class="line">            clip_ans[probs[<span class="number">0</span>].argsort()[::-<span class="number">1</span>][<span class="number">0</span>]] += <span class="number">1</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">print</span>(<span class="string">&quot;clip:&quot;</span>, clip_ans, scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))])</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 根据统计结果确定场景类别</span></span><br><span class="line">    <span class="keyword">if</span> scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))] <span class="keyword">in</span> [<span class="string">&#x27;lush green valley&#x27;</span>, <span class="string">&#x27;car tunnel in the mountains&#x27;</span>, <span class="string">&#x27;snowy mountain valley&#x27;</span>, <span class="string">&#x27;quiet suburban street&#x27;</span>, <span class="string">&#x27;open highway in the countryside&#x27;</span>]:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;suburban&#x27;</span></span><br><span class="line">    <span class="keyword">elif</span> scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))] <span class="keyword">in</span> [<span class="string">&#x27;The city highway&#x27;</span>, <span class="string">&#x27;open street in the city&#x27;</span>, <span class="string">&#x27;city street at daylight&#x27;</span>, <span class="string">&#x27;Street on a rainy night&#x27;</span>, <span class="string">&#x27;Street on a snowy night&#x27;</span>, <span class="string">&#x27;busy city street&#x27;</span>, <span class="string">&#x27;city streets at night&#x27;</span>]:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;city street&#x27;</span></span><br><span class="line">    <span class="keyword">elif</span> scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))] <span class="keyword">in</span> [<span class="string">&#x27;busy highway with heavy traffic&#x27;</span>]:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;expressway&#x27;</span></span><br><span class="line">    <span class="keyword">elif</span> scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))] <span class="keyword">in</span> [<span class="string">&#x27;subway tunnel&#x27;</span>]:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;tunnel&#x27;</span></span><br><span class="line">    <span class="keyword">elif</span> scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))] <span class="keyword">in</span> [<span class="string">&#x27;Indoor parking lot&#x27;</span>, <span class="string">&#x27;urban gas station at night&#x27;</span>, <span class="string">&#x27;crowded shopping mall parking lot&#x27;</span>]:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;parking-lot&#x27;</span></span><br><span class="line">    <span class="keyword">elif</span> scerario_clip[clip_ans.index(<span class="built_in">max</span>(clip_ans))] <span class="keyword">in</span> [<span class="string">&#x27;rural gas station in daylight&#x27;</span>]:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;gas or charging stations&#x27;</span></span><br><span class="line">    <span class="keyword">else</span>:</span><br><span class="line">        single_frame_result[<span class="string">&#x27;scerario&#x27;</span>] = <span class="string">&#x27;unknown&#x27;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment"># 将单个视频的测试结果添加到总体测试结果中</span></span><br><span class="line">    submit_json_scerario[<span class="string">&quot;test_results&quot;</span>].append(single_frame_result)</span><br></pre></td></tr></table></figure>
<h4 id="推理其余杂项"><a href="#推理其余杂项" class="headerlink" title="推理其余杂项"></a>推理其余杂项</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">data_processing</span>(<span class="params">results</span>):</span><br><span class="line">    <span class="comment"># 初始化结果字典</span></span><br><span class="line">    ans = &#123;</span><br><span class="line">        <span class="string">&#x27;ans&#x27;</span>: []</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> i, result <span class="keyword">in</span> <span class="built_in">enumerate</span>(results):</span><br><span class="line">        <span class="comment"># 初始化当前结果的字典</span></span><br><span class="line">        this = &#123;</span><br><span class="line">            <span class="string">&#x27;frame_count&#x27;</span>: i,</span><br><span class="line">            <span class="string">&#x27;name&#x27;</span>: [names[result[<span class="number">0</span>].boxes.cls.cpu().numpy()[j]] <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(result[<span class="number">0</span>].boxes.cls.cpu().numpy()))],  <span class="comment"># 标签名称</span></span><br><span class="line">            <span class="string">&#x27;conf&#x27;</span>: result[<span class="number">0</span>].boxes.conf.cpu().numpy(),  <span class="comment"># 标签置信度</span></span><br><span class="line">            <span class="string">&#x27;box&#x27;</span>: result[<span class="number">0</span>].boxes.xyxy.cpu().numpy().astype(<span class="built_in">int</span>)</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment"># 将当前结果添加到总体结果字典中</span></span><br><span class="line">        ans[<span class="string">&#x27;ans&#x27;</span>].append(this)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> ans</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_crossroads</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果某个标签为 &#x27;traffic light&#x27; 的数量大于等于 2，返回 True</span></span><br><span class="line">        <span class="keyword">if</span> re[<span class="string">&#x27;name&#x27;</span>].count(<span class="string">&#x27;traffic light&#x27;</span>) &gt;= <span class="number">2</span>:</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果没有满足条件的结果，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_manhole</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果某个标签为 &#x27;manhole cover&#x27;，并且置信度大于 0.7，返回 True</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;manhole cover&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][re[<span class="string">&#x27;name&#x27;</span>].index(<span class="string">&#x27;manhole cover&#x27;</span>)] &gt; <span class="number">0.7</span>:</span><br><span class="line">                <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果没有满足条件的结果，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">calculate_box_area</span>(<span class="params">box</span>):</span><br><span class="line">    <span class="comment"># 计算边界框的面积</span></span><br><span class="line">    width = <span class="built_in">abs</span>(box[<span class="number">2</span>] - box[<span class="number">0</span>])</span><br><span class="line">    height = <span class="built_in">abs</span>(box[<span class="number">3</span>] - box[<span class="number">1</span>])</span><br><span class="line">    area = width * height</span><br><span class="line">    <span class="keyword">return</span> area</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_traffic_cone</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 初始化置信度之和</span></span><br><span class="line">    sum_conf = <span class="number">0</span></span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果结果中包含 &#x27;traffic cone&#x27; 标签</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;traffic cone&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="comment"># 找到 &#x27;traffic cone&#x27; 在标签列表中的索引</span></span><br><span class="line">            idx = [index <span class="keyword">for</span> index, value <span class="keyword">in</span> <span class="built_in">enumerate</span>(re[<span class="string">&#x27;name&#x27;</span>]) <span class="keyword">if</span> value == <span class="string">&#x27;traffic cone&#x27;</span>]</span><br><span class="line">            <span class="comment"># 遍历所有 &#x27;traffic cone&#x27; 的索引</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> idx:</span><br><span class="line">                <span class="comment"># 打印当前 &#x27;traffic cone&#x27; 的面积和置信度</span></span><br><span class="line">                <span class="built_in">print</span>(calculate_box_area(re[<span class="string">&#x27;box&#x27;</span>][i]), re[<span class="string">&#x27;conf&#x27;</span>][i])</span><br><span class="line">                <span class="comment"># 如果置信度大于 0.5 且面积小于 20000，返回 True</span></span><br><span class="line">                <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][i] &gt; <span class="number">0.5</span> <span class="keyword">and</span> calculate_box_area(re[<span class="string">&#x27;box&#x27;</span>][i]) &lt; <span class="number">20000</span>:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">                <span class="comment"># 如果面积小于 20000，累加置信度</span></span><br><span class="line">                <span class="keyword">elif</span> calculate_box_area(re[<span class="string">&#x27;box&#x27;</span>][i]) &lt; <span class="number">20000</span>:</span><br><span class="line">                    sum_conf += re[<span class="string">&#x27;conf&#x27;</span>][i]</span><br><span class="line">    <span class="comment"># 如果累加的置信度大于等于 0.5，返回 True；否则返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span> <span class="keyword">if</span> sum_conf &lt; <span class="number">0.5</span> <span class="keyword">else</span> <span class="literal">True</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_police</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果结果中包含 &#x27;police car&#x27; 标签</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;police car&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="comment"># 找到 &#x27;police car&#x27; 在标签列表中的索引</span></span><br><span class="line">            idx = [index <span class="keyword">for</span> index, value <span class="keyword">in</span> <span class="built_in">enumerate</span>(re[<span class="string">&#x27;name&#x27;</span>]) <span class="keyword">if</span> value == <span class="string">&#x27;police car&#x27;</span>]</span><br><span class="line">            <span class="comment"># 遍历所有 &#x27;police car&#x27; 的索引</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> idx:</span><br><span class="line">                <span class="comment"># 如果置信度大于 0.5，返回 True</span></span><br><span class="line">                <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][i] &gt; <span class="number">0.5</span>:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果未检测到 &#x27;police car&#x27; 或所有检测到的 &#x27;police car&#x27; 置信度均不大于 0.5，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_truck</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果结果中包含 &#x27;truck&#x27; 标签</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;truck&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="comment"># 找到 &#x27;truck&#x27; 在标签列表中的索引</span></span><br><span class="line">            idx = [index <span class="keyword">for</span> index, value <span class="keyword">in</span> <span class="built_in">enumerate</span>(re[<span class="string">&#x27;name&#x27;</span>]) <span class="keyword">if</span> value == <span class="string">&#x27;truck&#x27;</span>]</span><br><span class="line">            <span class="comment"># 遍历所有 &#x27;truck&#x27; 的索引</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> idx:</span><br><span class="line">                <span class="comment"># 如果置信度大于 0.5，返回 True</span></span><br><span class="line">                <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][i] &gt; <span class="number">0.5</span>:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果未检测到 &#x27;truck&#x27; 或所有检测到的 &#x27;truck&#x27; 置信度均不大于 0.5，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_bus</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果结果中包含 &#x27;bus&#x27; 标签</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;bus&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="comment"># 找到 &#x27;bus&#x27; 在标签列表中的索引</span></span><br><span class="line">            idx = [index <span class="keyword">for</span> index, value <span class="keyword">in</span> <span class="built_in">enumerate</span>(re[<span class="string">&#x27;name&#x27;</span>]) <span class="keyword">if</span> value == <span class="string">&#x27;bus&#x27;</span>]</span><br><span class="line">            <span class="comment"># 遍历所有 &#x27;bus&#x27; 的索引</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> idx:</span><br><span class="line">                <span class="comment"># 如果置信度大于 0.6，返回 True</span></span><br><span class="line">                <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][i] &gt; <span class="number">0.6</span>:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果未检测到 &#x27;bus&#x27; 或所有检测到的 &#x27;bus&#x27; 置信度均不大于 0.6，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_other</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果结果中包含 &#x27;others&#x27; 标签</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;others&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="comment"># 找到 &#x27;others&#x27; 在标签列表中的索引</span></span><br><span class="line">            idx = [index <span class="keyword">for</span> index, value <span class="keyword">in</span> <span class="built_in">enumerate</span>(re[<span class="string">&#x27;name&#x27;</span>]) <span class="keyword">if</span> value == <span class="string">&#x27;others&#x27;</span>]</span><br><span class="line">            <span class="comment"># 遍历所有 &#x27;others&#x27; 的索引</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> idx:</span><br><span class="line">                <span class="comment"># 如果置信度大于 0.3，返回 True</span></span><br><span class="line">                <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][i] &gt; <span class="number">0.3</span>:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果未检测到 &#x27;others&#x27; 或所有检测到的 &#x27;others&#x27; 置信度均不大于 0.3，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">is_people</span>(<span class="params">res</span>):</span><br><span class="line">    <span class="comment"># 遍历结果列表</span></span><br><span class="line">    <span class="keyword">for</span> re <span class="keyword">in</span> res:</span><br><span class="line">        <span class="comment"># 如果结果中包含 &#x27;person&#x27; 标签</span></span><br><span class="line">        <span class="keyword">if</span> <span class="string">&#x27;person&#x27;</span> <span class="keyword">in</span> re[<span class="string">&#x27;name&#x27;</span>]:</span><br><span class="line">            <span class="comment"># 找到 &#x27;person&#x27; 在标签列表中的索引</span></span><br><span class="line">            idx = [index <span class="keyword">for</span> index, value <span class="keyword">in</span> <span class="built_in">enumerate</span>(re[<span class="string">&#x27;name&#x27;</span>]) <span class="keyword">if</span> value == <span class="string">&#x27;person&#x27;</span>]</span><br><span class="line">            <span class="comment"># 遍历所有 &#x27;person&#x27; 的索引</span></span><br><span class="line">            <span class="keyword">for</span> i <span class="keyword">in</span> idx:</span><br><span class="line">                <span class="comment"># 如果置信度大于 0.6，返回 True</span></span><br><span class="line">                <span class="keyword">if</span> re[<span class="string">&#x27;conf&#x27;</span>][i] &gt; <span class="number">0.6</span>:</span><br><span class="line">                    <span class="keyword">return</span> <span class="literal">True</span></span><br><span class="line">    <span class="comment"># 如果未检测到 &#x27;person&#x27; 或所有检测到的 &#x27;person&#x27; 置信度均不大于 0.6，返回 False</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">False</span></span><br></pre></td></tr></table></figure>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://datawhaler.feishu.cn/docx/L2bodJhfxoU11Yxrm04cY509nOe">2023全球智能汽车AI挑战赛：智能驾驶汽车虚拟仿真视频数据理解 - 飞书云文档 (feishu.cn)</a></p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_52309640/article/details/120940767">Python 计算机视觉（八）—— OpenCV 进行图像增强_opencv图像增强-CSDN博客</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://huaiyuechusan.github.io">SanShui</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://huaiyuechusan.github.io/archives/283f9737.html">https://huaiyuechusan.github.io/archives/283f9737.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://huaiyuechusan.github.io" target="_blank">SanShui的个人博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/">深度学习</a><a class="post-meta__tags" href="/tags/%E7%AB%9E%E8%B5%9B/">竞赛</a><a class="post-meta__tags" href="/tags/CV/">CV</a></div><div class="post_share"><div class="social-share" data-image="http://wallpaper.csun.site/?15" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" src="/img/wechat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/img/alipay.jpg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/archives/fab44cdf.html"><img class="prev-cover" src="http://wallpaper.csun.site/?7" onerror="onerror=null;src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">函数式编程和Python新核心特性</div></div></a></div><div class="next-post pull-right"><a href="/archives/d4b1abad.html"><img class="next-cover" src="http://wallpaper.csun.site/?22" onerror="onerror=null;src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">下载M3U8格式加密视频</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/archives/c3b7887e.html" title="从零入门CV图像竞赛（2024全球Deepfake攻防挑战赛）"><img class="cover" src="http://wallpaper.csun.site/?10" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2024-10-17</div><div class="title">从零入门CV图像竞赛（2024全球Deepfake攻防挑战赛）</div></div></a></div><div><a href="/archives/6e00b65.html" title="分类任务实现模型（投票式）集成代码模版"><img class="cover" src="http://wallpaper.csun.site/?13" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2024-10-17</div><div class="title">分类任务实现模型（投票式）集成代码模版</div></div></a></div><div><a href="/archives/a86ba09b.html" title="如何阅读PyTorch文档及常见PyTorch错误"><img class="cover" src="http://wallpaper.csun.site/?18" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2024-10-17</div><div class="title">如何阅读PyTorch文档及常见PyTorch错误</div></div></a></div><div><a href="/archives/76ef551b.html" title="快速入门PyTorch"><img class="cover" src="http://wallpaper.csun.site/?16" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2024-10-17</div><div class="title">快速入门PyTorch</div></div></a></div><div><a href="/archives/65941a46.html" title="推荐系统框架"><img class="cover" src="http://wallpaper.csun.site/?sun" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2024-10-17</div><div class="title">推荐系统框架</div></div></a></div><div><a href="/archives/638889b7.html" title="深度学习回归任务训练代码模版"><img class="cover" src="http://wallpaper.csun.site/?24" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2024-10-17</div><div class="title">深度学习回归任务训练代码模版</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="lv-container" data-id="city" data-uid="MTAyMC81OTEzMS8zNTU5Mw=="></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/./img/config_img/%E9%98%B3%E5%85%89%E5%B0%8F%E7%8C%AB.jpg" onerror="this.onerror=null;this.src='/./img/config_img/%E8%93%9D%E5%A4%A9.jpg'" alt="avatar"/></div><div class="author-info__name">SanShui</div><div class="author-info__description">今天不学习，明天变垃圾</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">16</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div><a id="card-info-btn" target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/huaiyuechusan"><i class="fa-sharp fa-solid fa-plane"></i><span>欢迎关注我的Github</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/huaiyuechusan" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://huaiyuechusan.github.io/atom.xml" target="_blank" title=""><i class="fas fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎来到SanShui的博客</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%AB%9E%E8%B5%9B%E6%80%BB%E7%BB%93%EF%BC%9A%E6%99%BA%E8%83%BD%E9%A9%BE%E9%A9%B6%E6%B1%BD%E8%BD%A6%E8%99%9A%E6%8B%9F%E4%BB%BF%E7%9C%9F%E8%A7%86%E9%A2%91%E6%95%B0%E6%8D%AE%E7%90%86%E8%A7%A3"><span class="toc-text">竞赛总结：智能驾驶汽车虚拟仿真视频数据理解</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%9B%E4%BA%8B%E8%83%8C%E6%99%AF"><span class="toc-text">赛事背景</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%9B%E4%BA%8B%E4%BB%BB%E5%8A%A1"><span class="toc-text">赛事任务</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E8%AF%B4%E6%98%8E"><span class="toc-text">数据说明</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%96%87%E6%9C%AC%E6%8F%8F%E8%BF%B0%E7%BB%93%E6%9E%84%E6%A0%91"><span class="toc-text">文本描述结构树</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%8A%E4%BC%A0json%E6%A0%BC%E5%BC%8F%E7%A4%BA%E4%BE%8B"><span class="toc-text">上传json格式示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AF%84%E6%B5%8B%E6%8C%87%E6%A0%87"><span class="toc-text">评测指标</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A7%A3%E9%A2%98%E6%80%9D%E8%B7%AF"><span class="toc-text">解题思路</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%80%9D%E8%B7%AF"><span class="toc-text">基本思路</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E9%98%B6%E6%80%9D%E8%B7%AF"><span class="toc-text">进阶思路</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%A4%9A%E6%A8%A1%E6%80%81%E5%A4%A7%E6%A8%A1%E5%9E%8BCLIP%E7%AE%80%E4%BB%8B"><span class="toc-text">多模态大模型CLIP简介</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%A7%E4%BD%AC%E4%BB%A3%E7%A0%81%E8%A7%A3%E8%AF%BB"><span class="toc-text">大佬代码解读</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A8%E7%90%86%E5%A4%A9%E6%B0%94%EF%BC%8C%E6%97%B6%E9%97%B4%E5%92%8C%E9%81%93%E8%B7%AF%E7%BB%93%E6%9E%84"><span class="toc-text">推理天气，时间和道路结构</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A8%E7%90%86%E6%9C%80%E8%BF%91%E4%BA%A4%E9%80%9A%E5%8F%82%E4%B8%8E%E8%80%85"><span class="toc-text">推理最近交通参与者</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A8%E7%90%86%E8%87%AA%E8%BD%A6%E8%A1%8C%E4%B8%BA"><span class="toc-text">推理自车行为</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A8%E7%90%86%E5%9C%BA%E6%99%AF"><span class="toc-text">推理场景</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8E%A8%E7%90%86%E5%85%B6%E4%BD%99%E6%9D%82%E9%A1%B9"><span class="toc-text">推理其余杂项</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%82%E8%80%83"><span class="toc-text">参考</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/archives/6ca065c5.html" title="SanShui API 使用教程"><img src="http://wallpaper.csun.site/?abc" onerror="this.onerror=null;this.src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="SanShui API 使用教程"/></a><div class="content"><a class="title" href="/archives/6ca065c5.html" title="SanShui API 使用教程">SanShui API 使用教程</a><time datetime="2025-03-13T13:21:12.311Z" title="更新于 2025-03-13 21:21:12">2025-03-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/archives/b5700173.html" title="微信小程序定时订阅消息问题"><img src="http://wallpaper.csun.site/?25" onerror="this.onerror=null;this.src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="微信小程序定时订阅消息问题"/></a><div class="content"><a class="title" href="/archives/b5700173.html" title="微信小程序定时订阅消息问题">微信小程序定时订阅消息问题</a><time datetime="2024-10-17T12:04:53.379Z" title="更新于 2024-10-17 20:04:53">2024-10-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/archives/638889b7.html" title="深度学习回归任务训练代码模版"><img src="http://wallpaper.csun.site/?24" onerror="this.onerror=null;this.src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="深度学习回归任务训练代码模版"/></a><div class="content"><a class="title" href="/archives/638889b7.html" title="深度学习回归任务训练代码模版">深度学习回归任务训练代码模版</a><time datetime="2024-10-17T12:04:09.066Z" title="更新于 2024-10-17 20:04:09">2024-10-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/archives/7cb9f0a8.html" title="通过nginx访问tomcat中SpringMVC应用"><img src="http://wallpaper.csun.site/?23" onerror="this.onerror=null;this.src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="通过nginx访问tomcat中SpringMVC应用"/></a><div class="content"><a class="title" href="/archives/7cb9f0a8.html" title="通过nginx访问tomcat中SpringMVC应用">通过nginx访问tomcat中SpringMVC应用</a><time datetime="2024-10-17T12:02:23.321Z" title="更新于 2024-10-17 20:02:23">2024-10-17</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/archives/d4b1abad.html" title="下载M3U8格式加密视频"><img src="http://wallpaper.csun.site/?22" onerror="this.onerror=null;this.src='/./img/config_img/%E5%A4%9C%E6%99%9A.jpg'" alt="下载M3U8格式加密视频"/></a><div class="content"><a class="title" href="/archives/d4b1abad.html" title="下载M3U8格式加密视频">下载M3U8格式加密视频</a><time datetime="2024-10-17T12:02:02.720Z" title="更新于 2024-10-17 20:02:02">2024-10-17</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('http://wallpaper.csun.site/?15')"><div id="footer-wrap"><div class="footer_custom_text">更多内容查看<a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/huaiyuechusan/">我的GitHub</a> ！</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight, 500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    chtml: {
      scale: 1.1
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        insertScript: [200, () => {
          document.querySelectorAll('mjx-container').forEach(node => {
            if (node.hasAttribute('display')) {
              btf.wrap(node, 'div', { class: 'mathjax-overflow' })
            } else {
              btf.wrap(node, 'span', { class: 'mathjax-overflow' })
            }
          });
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax/es5/tex-mml-chtml.min.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>function loadLivere () {
  if (typeof LivereTower === 'object') {
    window.LivereTower.init()
  }
  else {
    (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
    })(document, 'script');
  }
}

if ('Livere' === 'Livere' || !true) {
  if (true) btf.loadComment(document.getElementById('lv-container'), loadLivere)
  else loadLivere()
}
else {
  function loadOtherComment () {
    loadLivere()
  }
}</script></div><div class="aplayer no-destroy" data-id="875151895" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true" data-volume="0.5"> </div><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="Nice,To,Meet,YOU" data-fontsize="15px" data-random="false" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["meta[property=\"og:image\"]","meta[property=\"og:title\"]","meta[property=\"og:url\"]","head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
    function butterfly_categories_card_injector_config(){
      var parent_div_git = document.getElementById('recent-posts');
      var item_html = '<style>li.categoryBar-list-item{width:32.3%;}.categoryBar-list{max-height: 380px;overflow:auto;}.categoryBar-list::-webkit-scrollbar{width:0!important}@media screen and (max-width: 650px){.categoryBar-list{max-height: 320px;}}</style><div class="recent-post-item" style="height:auto;width:100%;padding:0px;"><div id="categoryBar"><ul class="categoryBar-list"><li class="categoryBar-list-item" style="background:url(./img/config_img/image-20231112202739060-2023-11-1220-27-56.png);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/AI大模型/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">AI大模型</a><span class="categoryBar-list-count">3</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/202310300007012-2023-11-1123-30-55.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/微信小程序/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">微信小程序</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/Girl-2023-11-2221_46_26.png);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/爬虫/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">爬虫</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/202310300007316-2023-11-1123-30-57.png);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/深度学习/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">深度学习</a><span class="categoryBar-list-count">4</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/Cat-2023-11-2221-47-16.png);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/大数据/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">大数据</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/preview-2024-1-8-17-36-46.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/PyTorch/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">PyTorch</a><span class="categoryBar-list-count">3</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/preview-2024-1-8-17-36-11.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/多模态推荐系统/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">多模态推荐系统</a><span class="categoryBar-list-count">1</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/Starry-Night-in-Anime-Wallpaper-2023-11-2221-46-39.png);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/学习总结/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">学习总结</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/page_img/wallhaven-y8lqo7.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/竞赛/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">竞赛</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/preview-2024-1-8-17-34-25.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/Python/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">Python</a><span class="categoryBar-list-count">4</span><span class="categoryBar-list-descr"></span></li><li class="categoryBar-list-item" style="background:url(./img/config_img/preview-2024-1-8-17-37-57.jpg);"> <a class="categoryBar-list-link" onclick="pjax.loadUrl(&quot;categories/Liunx/&quot;);" href="javascript:void(0);" rel="external nofollow noreferrer">Liunx</a><span class="categoryBar-list-count">2</span><span class="categoryBar-list-descr"></span></li></ul></div></div>';
      console.log('已挂载butterfly_categories_card')
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
      }
    if( document.getElementById('recent-posts') && (location.pathname ==='/'|| '/' ==='all')){
    butterfly_categories_card_injector_config()
    }
  </script><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><p id="ghbdages"><a class="github-badge" target="_blank" href="https://hexo.io/" rel="external nofollow noreferrer" style="margin-inline:5px" data-title="博客框架为Hexo_v6.2.0" title=""><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" rel="external nofollow noreferrer" style="margin-inline:5px" data-title="主题版本Butterfly_v4.3.1" title=""><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" alt=""/></a><a class="github-badge" target="_blank" href="https://github.com/" rel="external nofollow noreferrer" style="margin-inline:5px" data-title="本站采用多线部署，主线路托管于Github Pages" title=""><img src="https://img.shields.io/badge/Hosted-Github Pages-brightgreen?style=flat&amp;logo=Github" alt=""/></a><a class="github-badge" target="_blank" href="https://gitee.com/" rel="external nofollow noreferrer" style="margin-inline:5px" data-title="本站采用多线部署，备用线路托管于Gitee Pages" title=""><img src="https://img.shields.io/badge/Hosted-Gitee Pages-22DDDD?style=flat&amp;logo=Gitee" alt=""/></a><a class="github-badge" target="_blank" href="https://github.com/" rel="external nofollow noreferrer" style="margin-inline:5px" data-title="本站项目由Github托管" title=""><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&amp;logo=GitHub" alt=""/></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" style="margin-inline:5px" data-title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可" title=""><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" alt=""/></a></p>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="/./js/runtime.js"></script><!-- hexo injector body_end end --></body></html>